import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../../services/address.dart';
import '../../../services/dio_manager.dart';

class ForgetPasswordController extends GetxController{



  final TextEditingController mobileTextController = TextEditingController();

  final TextEditingController codeTextController = TextEditingController();
  final TextEditingController passWordController = TextEditingController();
  final TextEditingController passWordControlle1 = TextEditingController();

  var options = '+86';
  /// 忘记密码请求
  requestDataWithChangePassword(var mobile,var password,var code)async{

    var params = {
      'mobile':mobile.replaceAll(new RegExp(r"\s+\b|\b\s"), ""),
      'password':password,
      'code':code,
    };

    var json = await DioManager().kkRequest(Address.forgetPassword,bodyParams: params);
    if(json['errmsg']=='ok'){
      BotToast.showText(text: '${json['message']}');
      Get.back();
    }
    BotToast.showText(text: '${json['message']}');

  }
  ///忘记密码点击按钮
  tapClickForget(){
    if (mobileTextController.text.isEmpty) {
      // Toast.toast(context,msg: '请输入手机号码');
      BotToast.showText(text: '请输入手机号码');
      return;
    }
    if(!GetUtils.isPhoneNumber(mobileTextController.text)){
      BotToast.showText(text: '请输入正确的手机号码');
      return;
    }

    if(passWordController.text!=passWordControlle1.text){
      BotToast.showText(text: '两次密码不一样');
      return;
    }

    requestDataWithChangePassword(mobileTextController.text,passWordController.text,
        codeTextController.text);
  }


}